package com.itheima.sentinel.service.impl;//package com.itheima.sentinel.service;

import com.alibaba.csp.sentinel.adapter.spring.webmvc.callback.RequestOriginParser;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @Class: RequestOriginParserDefinition
 * @Package com.itheima.sentinel.service
 * @Description:调用来源
 * @Company: http://www.itheima.com/
 */
@Component
public class RequestOriginParserDefinition implements RequestOriginParser {
    /*
     * @Description: 根据httpServletRequest中的参数进行限制黑白名单
     * 此处以ip来做限制
     * @Method: parseOrigin
     * @Param: [httpServletRequest]
     * @Update:
     * @since: 1.0.0
     * @Return: java.lang.String
     *
     */
    @Override
    public String parseOrigin(HttpServletRequest httpServletRequest) {
        // 当前 流控应用 放在了请求参数里面，可以放到的地方有很多，比如 参数/请求头/session/等等
//        return httpServletRequest.getParameter("sourceName");
        System.out.println("==============================返回调用来源"
                + httpServletRequest.getRemoteAddr());
//        return "app";
        return httpServletRequest.getRemoteAddr();
    }
    
}
